<?php

namespace app\logic\im;

use think\facade\Config;
use app\common\library\TLSSigAPIv2;
use app\common\library\GuzzleTool;
use app\common\enum\LogChannelEnum;

class BaseLogic
{
    protected $im_config = [];

    public function __construct()
    {
        $this->im_config = Config::get('im.tencent');
    }

    protected function im()
    {
        return new TLSSigAPIv2(
            $this->im_config['sdkappid'],
            $this->im_config['key']
        );
    }

    protected function postraw($path, $data)
    {
        $im_admin_id = $this->im_config['im_admin_id'];
        $usersig = $this->im()->genUserSig($im_admin_id, 300);
        $url = $this->im_config['apiurl'] . $path . '?sdkappid=' . $this->im_config['sdkappid'] . '&identifier=' . $im_admin_id . '&usersig=' . $usersig . '&random=' . rand(0, 4294967295) . '&contenttype=json';

        return json_decode(GuzzleTool::postraw(LogChannelEnum::IM, $url, json_encode($data)), true);
    }
}